import { Queue } from "./interface";
import { getFinalState } from "./processQueue";

interface TestCaseProps {
  baseState: number;
  queue: Queue;
  expected: number;
}
function increment(n: number) {
  return n + 1;
}

increment.toString = () => "n=>n+1";

function TestCase({ baseState, queue, expected }: TestCaseProps) {
  const actual = getFinalState(baseState, queue);

  return (
    <>
      <p>
        初始 state: <b>{baseState}</b>
      </p>
      <p>
        队列: <b>[{queue.join(", ")}]</b>
      </p>
      <p>
        预期结果: <b>{expected}</b>
      </p>
      <p
        style={{
          color: actual === expected ? "green" : "red"
        }}
      >
        你的结果: <b>{actual}</b>({actual === expected ? "正确" : "错误"})
      </p>
    </>
  );
}

function StatusQueue() {
  return (
    <>
      <TestCase baseState={0} queue={[1, 1, 1]} expected={1} />
      <hr />
      <TestCase baseState={0} queue={[increment, increment, increment]} expected={3} />
      <hr />
      <TestCase baseState={0} queue={[5, increment]} expected={6} />
      <hr />
      <TestCase baseState={0} queue={[5, increment, 42]} expected={42} />
    </>
  );
}

export default StatusQueue;
